<?php
/**
 * Created by PhpStorm.
 * User: tangchao
 * Date: 19-4-20
 * Time: 下午4:31
 */

namespace Lib;

use Lib\Db\MySQLi;

class User
{
    public $id;
    public $name;

    protected $db;

    function __construct($id)
    {
        $this->db = new MySQLi();
        $this->db->connect('127.0.0.1','root','st826115','es_pool');
        $res = $this->db->query("select * from user where id=$id limit 1");
        $data = $res->fetch_assoc();
        $this->id = $id;
        $this->name = $data['name'];
    }

    function __destruct()
    {
        $this->db->query("update mapping set name = '{$this->name}' where id={$this->id}");
    }
}